# Tanım: Java Servlet 3.1 ve JavaServer Pages 2.3 teknolojilerinin açık kaynaklı uygulaması
# URL: http://tomcat.apache.org/
# Paketçi: Cihan_Alkan 
# Gerekler: openjdk

isim=tomcat8
surum=8.0.47
devir=1

kaynak=(https://archive.apache.org/dist/tomcat/tomcat-8/v${surum}/bin/apache-tomcat-${surum}.tar.gz)

derle() {

_gid_log=19
_gid_tomcat=57
_uid_tomcat=57

  cd "${SRC}/apache-tomcat-${surum}"

  # Tomcat general files
  install -dm755 "${PKG}"/usr/share/{,java/}${isim}
  cp -r bin "${PKG}"/usr/share/${isim}
  # commons-daemon and tomcat-natives are packaged on their own
  rm "${PKG}"/usr/share/${isim}/bin/{*.bat,commons-daemon*,tomcat-native.tar.gz}
  ln -s /usr/share/java/commons-daemon.jar "${PKG}"/usr/share/${isim}/bin/commons-daemon.jar

  install -m644 lib/* "${PKG}"/usr/share/java/${isim}
  # eclipse-ecj is packaged on its own
  rm "${PKG}"/usr/share/java/${isim}/ecj-*.jar
  ln -s ../eclipse-ecj.jar "${PKG}"/usr/share/java/${isim}/ecj.jar

  ln -s /usr/share/java/${isim} "${PKG}"/usr/share/${isim}/lib

  # We log through systemd but this would still be required for stock Tomcat logging
  install -dm775 -o ${_uid_tomcat} -g ${_gid_log} "${PKG}"/var/log/${isim}
  ln -s /var/log/${isim} "${PKG}"/usr/share/${isim}/logs
  touch "${PKG}"/var/log/${isim}/catalina.{out,err}
  chgrp ${_gid_log} "${PKG}"/var/log/${isim}/catalina.{out,err}

  install -dm775 "${PKG}"/etc/${isim}
  install -g ${_gid_tomcat} -m640 conf/* "${PKG}"/etc/${isim}
  install -d -g ${_gid_tomcat} -m775 "${PKG}"/etc/${isim}/Catalina
  ln -s /etc/${isim} "${PKG}"/usr/share/${isim}/conf

  install -dm775 "${PKG}"/var/lib/${isim}
  cp -r webapps "${PKG}"/var/lib/${isim}
  chown -R ${_uid_tomcat}:${_gid_tomcat} "${PKG}"/var/lib/${isim}
  chmod 775 "${PKG}"/var/lib/${isim}/webapps
  ln -s /var/lib/${isim}/webapps "${PKG}"/usr/share/${isim}/webapps

  install -dm1777 "${PKG}"/var/tmp
  install -dm775 -o ${_uid_tomcat} -g ${_gid_tomcat} "${PKG}"/var/tmp/${isim}/{temp,work}
  ln -s /var/tmp/${isim}/temp "${PKG}"/usr/share/${isim}/temp
  ln -s /var/tmp/${isim}/work "${PKG}"/usr/share/${isim}/work

}
